<template>
  <div id="infor">
    <nav-header></nav-header>
    <div class="infor-content">
      <sidebar
        :tags="tags"
        @conIndex="getIndex($event)"
        ref="father"
        :defaultIndex="defaultIndex"
      ></sidebar>
      <div class="infor-right">
        <div class="account">来闻认证</div>
        <div class="infor">
          <div class="infor-title">
            <div class="infor-text">个人认证</div>
            <div class="infor-icon">
              <img src="../assets/imgs/hv.png" alt="" />
            </div>
          </div>
          <div class="person-content">
            <div class="person-title">满足以下条件即可申请</div>
            <div class="person-tags">
              <div class="single-tag">
                <div class="person-icon">
                  <img src="../assets/imgs/fb.png" alt="" />
                </div>
                <div class="person-prompt">发布百字以上点评≥100个</div>
                <div class="person-state giftNum" v-if="person.show">{{person.articleCount}}/100</div>
                <div class="person-state" v-else>已完成</div>
              </div>
              <div class="single-tag">
                <div class="person-icon">
                  <img src="../assets/imgs/sygb.png" alt="" />
                </div>
                <div class="person-prompt">收到的荧光棒≥5000根</div>
                <div class="person-state giftNum" v-if="person.giftShow">
                  {{person.stickCount}}/5000
                </div>
                <div class="person-state" v-else>已完成</div>
              </div>
            </div>
            <div class="person-btn" v-if="person.state == 2">已申请</div>
            <div class="request" v-else @click="getPersonRequest">立即申请</div>
          </div>
          <div class="infor-title company">
            <div class="infor-text">企业认证</div>
            <div class="infor-icon">
              <img src="../assets/imgs/lv.png" alt="" />
            </div>
          </div>
          <div class="person-content">
            <div class="person-title">满足以下条件即可申请</div>
            <div class="person-tags">
              <div class="single-tag">
                <div class="person-icon">
                  <img src="../assets/imgs/sfz.png" alt="" />
                </div>
                <div class="person-prompt">法人身份证</div>
                <div
                  class="person-state link"
                  @click="goHtml(0)"
                  v-if="company.personState == 0"
                >
                  去填写>
                </div>
                <div
                  class="person-state link disableBtn"
                  v-else
                  @click="finish"
                >
                  已填写>
                </div>
              </div>
              <div class="single-tag">
                <div class="person-icon">
                  <img src="../assets/imgs/s.png" alt="" />
                </div>
                <div class="person-prompt">申请书</div>
                <div
                  class="person-state link"
                  @click="goHtml(1)"
                  v-if="company.requestState == 0"
                >
                  去上传>
                </div>
                <div
                  class="person-state link disableBtn"
                  v-else
                  @click="finish"
                >
                  已上传>
                </div>
              </div>
            </div>
            <div class="person-tags">
              <div class="single-tag">
                <div class="person-icon">
                  <img src="../assets/imgs/zz.png" alt="" />
                </div>
                <div class="person-prompt">营业执照</div>
                <div
                  class="person-state link"
                  @click="goHtml(2)"
                  v-if="company.businessState == 0"
                >
                  去上传>
                </div>
                <div
                  class="person-state link disableBtn"
                  v-else
                  @click="finish"
                >
                  已上传>
                </div>
              </div>
            </div>
            <div class="person-btn" v-if="company.state == 2">申请通过</div>
            <div class="request" v-if="company.state == 1"  @click="alreadyRequest">申请中</div>
            <div class="request" v-if="company.state == 0" @click="getRequest">立即申请</div>
          </div>
        </div>
      </div>
    </div>
    <nav-footer ref="child"> </nav-footer>
  </div>
</template>

<script>
import Sidebar from "../components/Sidebar";
import NavHeader from "../components/Header";
import NavFooter from "../components/Footer";
import { provinceAndCityData, CodeToText } from "element-china-area-data";
export default {
  
  data() {
    return {
      tags: [{ name: "来闻认证" }],
      defaultIndex: 0,
      person: "",
      company: "",
    };
  },
  components: {
    Sidebar,
    NavHeader,
    NavFooter,
  },
  created() {
    //个人认证进度查询
    this.$fetch(`/laiwen/personal/frontend/count`, {}).then((res) => {
      console.log(res);
      this.person = res.person;
      this.$set(this.person, "show", true);
      this.$set(this.person, "giftShow", true);
      if (this.person.articleCount > 100) {
        this.person.show = false;
        this.person.giftShow = false;
      }
    });
    //企业认证进度查询
    this.$post(`/laiwen/business/frontend/getstate`, {}).then((res) => {
      this.company = res.state;
    });
  },
  methods: {
    //接受子组件index
    getIndex(e) {
      console.log(e);
    },
    //跳转到申请
    goHtml(e) {
      this.$router.push({
        path: "/idcheck",
        query: { index: e },
      });
    },
    //企业申请操作
    getRequest() {
      let that = this;
      if (
        that.company.businessState == 1 &&
        that.company.personState == 1 &&
        that.company.requestState == 1
      ) {
        //申请的url
        if (that.company.state != 1) {
          this.$message.warning("请耐心等待审核哦");
          that.company.state = 1;
          that.$post(`/laiwen/business/frontend/request`, {}).then((res) => {});
        } else {
          this.$message.warning("请耐心等待审核哦");
        }
      } else {
        this.$message.error("请补全资料后再点击申请哦");
      }
    },
    //个人申请操作
    getPersonRequest() {
      let that = this;
      console.log(that.person);
      if (that.person.state == 1) {
        //申请的url
        that.person.person.state = 2;
        that
          .$post(`/laiwen/personal/frontend/identify`, {}, "post")
          .then((res) => {});
      } else if (that.person.state == 0) {
        this.$message.error("还没有拥有这个资格哦");
      }
    },
    //已填写的模态窗
    finish() {
      this.$message.warning("亲亲已填写过了不可以在点击了哦");
    },
    alreadyRequest(){
     this.$message.warning('正在申请中')
    },
  },
  mounted() {
    this.getRem(1920, 100);
  },
};
</script>

<style scoped src="../assets/css/request.css"></style>
